// <copyright file="StartUndoInstruction.cs" company="Codeplex project Eco.Contrib"> 
// The MIT License (MIT) 
// </copyright> 
// <author>Peter Buchmann</author> 

namespace Eco.Contrib
{
    using System;
    using System.Collections.Generic;
    using Eco.ObjectRepresentation;
    using Eco.Services;
    using Eco.UmlCodeAttributes;

    /// <summary>
    /// StartUndoInstruction: Instruction that starts a undo bl
    /// </summary>
    public partial class StartUndoInstruction
    {
        /// <summary>
        /// Executes the function.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="variableList">The variable list.</param>
        /// <returns>Return value of executed function</returns>
        [UmlElement(Id = "106ed66a-bfee-44d7-bb18-031be92dfc38")]
        protected internal override IElement ExecuteFunction(IEcoServiceProvider serviceProvider, IModifiableVariableList variableList)
        {
            serviceProvider.GetEcoService<IUndoService>().StartUndoBlock();
            return null;
        }

        /// <summary>
        /// Inits the specified tokens.
        /// </summary>
        /// <param name="tokens">The tokens.</param>
        [UmlElement(Id = "a9c5fc33-f88e-47a8-958d-c58670b350ae")]
        protected internal override void Init(Dictionary<IList<EslToken>, Type> tokens)
        {
            List<EslToken> tokenList = new List<EslToken>();
            tokenList.Add(new EslToken(EslTokenType.Word, "Start"));
            tokenList.Add(new EslToken(EslTokenType.Word, "Transaction"));
            tokens.Add(tokenList, this.GetType());
        }

        /// <summary>
        /// Parses the specified token list.
        /// </summary>
        /// <param name="tokenList">The token list.</param>
        /// <param name="ecoScript">The eco script.</param>
        /// <param name="fullExpression">if set to <c>true</c> [full expression].</param>
        [UmlElement(Id = "ac3351d2-b1fa-49e6-9d26-4504d50f5ca6")]
        protected internal override void Parse(IList<EslToken> tokenList, EcoScript ecoScript, bool fullExpression)
        {
            EslToken token = GetNextToken(tokenList);
            RememberEcoScript(ecoScript, token);
            token = GetNextToken(tokenList);

            if (fullExpression)
            {
                EslToken tokenEnd = GetNextToken(tokenList);
                AssertInstructionEnd(tokenEnd);
            }
        }
    }
}